package com.cskaoyan.mall.controller.promotion;

import com.cskaoyan.mall.bean.Topic;
import com.cskaoyan.mall.bean.vo.ResultVO;
import com.cskaoyan.mall.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/admin/topic")
public class TopicController {
    @Autowired
    TopicService topicService;
    @RequestMapping("list")
    public ResultVO queryTopicList(Integer page,Integer limit,String sort,String order,String title,String subtitle){
        HashMap<String,Object> map = topicService.queryTopicList(page,limit,sort,order,title,subtitle);
        return ResultVO.ok(map);
    }

    @PostMapping("create")
    public ResultVO createTopic(@RequestBody Topic topic){
        Topic topicVo = topicService.insertTopic(topic);
        return ResultVO.ok(topicVo);
    }

    @PostMapping("update")
    public ResultVO updateTopic(@RequestBody Topic topic){
        Topic topicVo = topicService.updateTopic(topic);
        return ResultVO.ok(topicVo);
    }

    @PostMapping("delete")
    public ResultVO deleteTopic(@RequestBody Topic topic){
        topicService.deleteTopic(topic.getId());
        return ResultVO.ok();
    }
}
